Hanye官网
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

[id].vue 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. <template>
  2. <div>
  3. <div class="w-full h-[55px] sm:h-[72px]"></div>
  4. <ErrorBoundary :error="error">
  5. <div v-if="isLoading" class="flex justify-center py-12">
  6. <!-- 加载中 -->
  7. <div
  8. class="animate-spin h-8 w-8 border-4 border-cyan-400 rounded-full border-t-transparent"
  9. ></div>
  10. </div>
  11. <div v-else>
  12. <!-- 面包屑导航 -->
  13. <div class="max-w-full mb-6 xl:px-2 lg:px-2 md:px-4 px-4 mt-6">
  14. <div class="max-w-screen-2xl mx-auto">
  15. <nuxt-link
  16. :to="`${homepagePath}/`"
  17. class="justify-start text-white/60 text-base font-normal"
  18. >{{ t("common.breadcrumb.home") }}</nuxt-link
  19. >
  20. <span class="text-white/60 text-base font-normal px-2"> / </span>
  21. <nuxt-link
  22. v-if="product?.category"
  23. :to="`${homepagePath}/products?audiences=${product.meta?.audiences}`"
  24. class="text-white/60 text-base font-normal"
  25. >{{
  26. product.meta?.audiences === 0
  27. ? t("common.personal")
  28. : t("common.business")
  29. }}</nuxt-link
  30. >
  31. <span class="text-white/60 text-base font-normal px-2"> / </span>
  32. <nuxt-link
  33. v-if="product?.category"
  34. :to="`${homepagePath}/products?category=${encodeURIComponent(
  35. product.category
  36. )}&audiences=${product.meta?.audiences}`"
  37. class="text-white/60 text-base font-normal"
  38. >{{ product.category }}</nuxt-link
  39. >
  40. <span class="text-white/60 text-base font-normal px-2"> / </span>
  41. <span class="text-white text-base font-normal">{{
  42. product?.title || product?.name
  43. }}</span>
  44. </div>
  45. </div>
  46. <!-- 产品详情内容 -->
  47. <div
  48. v-if="product"
  49. class="max-w-full mb-12 md:mb-20 lg:mb-32 xl:px-2 lg:px-2 md:px-4 px-4"
  50. >
  51. <div class="max-w-screen-2xl mx-auto">
  52. <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-16">
  53. <!-- 左侧产品图片 -->
  54. <div
  55. class="flex flex-col gap-6 lg:sticky lg:top-24 self-start select-none"
  56. >
  57. <!-- 主图展示 -->
  58. <div
  59. class="bg-zinc-900 rounded-lg p-8 relative overflow-hidden group aspect-square"
  60. >
  61. <!-- 主图容器 - Swiper -->
  62. <Swiper
  63. :modules="[Navigation, Pagination, EffectFade, Thumbs]"
  64. :slides-per-view="1"
  65. :pagination="{
  66. clickable: true,
  67. dynamicBullets: true,
  68. dynamicMainBullets: 3,
  69. }"
  70. :navigation="true"
  71. :effect="'fade'"
  72. :fade-effect="{ crossFade: true }"
  73. :thumbs="{ swiper: thumbsSwiper }"
  74. class="w-full h-full product-swiper"
  75. @swiper="swiperInstance = $event"
  76. @slideChange="currentSlideIndex = $event.activeIndex"
  77. >
  78. <SwiperSlide
  79. v-for="(image, slideIndex) in [
  80. product.image,
  81. ...(product.gallery || []),
  82. ]"
  83. :key="slideIndex"
  84. >
  85. <div class="relative w-full h-full">
  86. <!-- 当前图片 -->
  87. <img
  88. :src="image"
  89. :alt="`${product.name} - ${t('products.image', {
  90. index: slideIndex + 1,
  91. })}`"
  92. class="w-full h-full object-contain rounded-lg transition-all duration-500"
  93. :class="{
  94. 'opacity-0': isSlideThumbnailLoading[slideIndex],
  95. 'opacity-100':
  96. !isSlideThumbnailLoading[slideIndex] &&
  97. !slideThumbnailErrors[slideIndex],
  98. }"
  99. @load="handleSlideImageLoad(slideIndex)"
  100. @error="handleSlideImageError(slideIndex)"
  101. />
  102. <!-- 加载状态 -->
  103. <div
  104. v-if="isSlideThumbnailLoading[slideIndex]"
  105. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 z-10"
  106. >
  107. <div
  108. class="animate-spin h-8 w-8 border-4 border-cyan-400 rounded-full border-t-transparent"
  109. ></div>
  110. </div>
  111. <!-- 错误提示 -->
  112. <div
  113. v-if="slideThumbnailErrors[slideIndex]"
  114. class="absolute inset-0 flex items-center justify-center bg-red-900/50 z-20"
  115. >
  116. <div class="flex flex-col items-center gap-2">
  117. <span class="text-white">{{
  118. t("products.imageLoadError")
  119. }}</span>
  120. <button
  121. @click.stop="retryLoadSlideImage(slideIndex)"
  122. class="px-4 py-2 bg-cyan-400 text-white rounded-lg hover:bg-cyan-600 transition-colors duration-300"
  123. >
  124. {{ t("products.retry") }}
  125. </button>
  126. </div>
  127. </div>
  128. </div>
  129. </SwiperSlide>
  130. </Swiper>
  131. <!-- 全局加载状态 - 仅在所有图片都未加载完成时显示 -->
  132. <div
  133. v-if="isInitialLoading"
  134. class="absolute inset-0 flex items-center justify-center bg-zinc-900/80 z-30"
  135. >
  136. <div
  137. class="animate-spin h-12 w-12 border-4 border-cyan-400 rounded-full border-t-transparent"
  138. ></div>
  139. </div>
  140. </div>
  141. <!-- 缩略图列表 - Swiper -->
  142. <div
  143. class="relative bg-zinc-900 rounded-lg py-6 px-8 overflow-hidden product-thumbnail-container"
  144. >
  145. <Swiper
  146. :modules="[Navigation, Thumbs, FreeMode]"
  147. :slides-per-view="'auto'"
  148. :space-between="12"
  149. :free-mode="true"
  150. :watch-slides-progress="true"
  151. :navigation="{
  152. nextEl: '.swiper-thumb-next',
  153. prevEl: '.swiper-thumb-prev',
  154. }"
  155. class="thumbs-swiper"
  156. @swiper="thumbsSwiper = $event"
  157. >
  158. <SwiperSlide
  159. v-for="(image, index) in [
  160. product.image,
  161. ...(product.gallery || []),
  162. ]"
  163. :key="index"
  164. class="!w-16 !h-16 md:!w-20 md:!h-20 !flex-shrink-0 cursor-pointer transition-all duration-300 relative"
  165. >
  166. <div
  167. class="w-full h-full rounded-lg overflow-hidden thumbnail-fixed-size"
  168. :class="{
  169. 'ring-2 ring-cyan-400 ring-offset-2 ring-offset-zinc-900':
  170. currentSlideIndex === index,
  171. 'hover:ring-1 hover:ring-cyan-400/50 hover:ring-offset-1 hover:ring-offset-zinc-900':
  172. currentSlideIndex !== index,
  173. 'opacity-50':
  174. isSlideThumbnailLoading[index] ||
  175. slideThumbnailErrors[index],
  176. }"
  177. >
  178. <!-- 缩略图加载状态 -->
  179. <div
  180. v-if="isSlideThumbnailLoading[index]"
  181. class="absolute inset-0 flex items-center justify-center bg-zinc-800/50 rounded-lg z-10"
  182. >
  183. <div
  184. class="animate-spin h-4 w-4 border-2 border-cyan-400 rounded-full border-t-transparent"
  185. ></div>
  186. </div>
  187. <!-- 缩略图遮罩 -->
  188. <div
  189. class="absolute inset-0 transition-all duration-300 rounded-lg"
  190. :class="{
  191. 'bg-black/30': currentSlideIndex === index,
  192. 'bg-black/0 hover:bg-black/20':
  193. currentSlideIndex !== index,
  194. }"
  195. ></div>
  196. <img
  197. :src="image"
  198. :alt="`${product.name} - ${t('products.image', {
  199. index: index + 1,
  200. })}`"
  201. class="w-full h-full object-cover transition-all duration-300 rounded-lg"
  202. :class="{
  203. 'opacity-0': isSlideThumbnailLoading[index],
  204. 'opacity-100':
  205. !isSlideThumbnailLoading[index] &&
  206. !slideThumbnailErrors[index],
  207. 'hover:scale-110': currentSlideIndex !== index,
  208. }"
  209. @load="handleSlideImageLoad(index)"
  210. @error="handleSlideImageError(index)"
  211. />
  212. <!-- 缩略图错误提示 -->
  213. <div
  214. v-if="slideThumbnailErrors[index]"
  215. class="absolute inset-0 flex items-center justify-center bg-red-900/50 rounded-lg"
  216. >
  217. <div class="flex flex-col items-center gap-1">
  218. <span class="text-white text-xs">{{
  219. t("products.error")
  220. }}</span>
  221. <button
  222. @click.stop="retryLoadSlideImage(index)"
  223. class="px-2 py-1 bg-cyan-400 text-white text-xs rounded hover:bg-cyan-600 transition-colors duration-300"
  224. >
  225. {{ t("products.retry") }}
  226. </button>
  227. </div>
  228. </div>
  229. </div>
  230. </SwiperSlide>
  231. </Swiper>
  232. <!-- 缩略图导航按钮 -->
  233. <button
  234. class="swiper-thumb-prev absolute top-1/2 left-2 z-10 w-8 h-8 flex items-center justify-center bg-black/50 hover:bg-cyan-400 rounded-full transform -translate-y-1/2 transition-all duration-300"
  235. >
  236. <svg
  237. xmlns="http://www.w3.org/2000/svg"
  238. class="h-5 w-5 text-white"
  239. fill="none"
  240. viewBox="0 0 24 24"
  241. stroke="currentColor"
  242. >
  243. <path
  244. stroke-linecap="round"
  245. stroke-linejoin="round"
  246. stroke-width="2"
  247. d="M15 19l-7-7 7-7"
  248. />
  249. </svg>
  250. </button>
  251. <button
  252. class="swiper-thumb-next absolute top-1/2 right-2 z-10 w-8 h-8 flex items-center justify-center bg-black/50 hover:bg-cyan-400 rounded-full transform -translate-y-1/2 transition-all duration-300"
  253. >
  254. <svg
  255. xmlns="http://www.w3.org/2000/svg"
  256. class="h-5 w-5 text-white"
  257. fill="none"
  258. viewBox="0 0 24 24"
  259. stroke="currentColor"
  260. >
  261. <path
  262. stroke-linecap="round"
  263. stroke-linejoin="round"
  264. stroke-width="2"
  265. d="M9 5l7 7-7 7"
  266. />
  267. </svg>
  268. </button>
  269. </div>
  270. </div>
  271. <!-- 右侧产品信息 -->
  272. <div class="flex flex-col gap-8">
  273. <!-- 产品名称 -->
  274. <div class="bg-zinc-900 rounded-lg p-2 md:p-6">
  275. <h1 class="text-white text-3xl font-medium mb-4">
  276. {{ product.title || product.name }}
  277. </h1>
  278. <div
  279. class="text-[#71717A] text-sm md:text-base leading-relaxed"
  280. >
  281. {{ product.summary }}
  282. </div>
  283. </div>
  284. <!-- 产品参数 -->
  285. <div
  286. class="bg-zinc-900 rounded-lg p-2 md:p-6 text-sm md:text-base"
  287. >
  288. <div class="grid grid-cols-1 gap-4">
  289. <div
  290. class="flex justify-between items-center gap-2 py-2 border-b border-zinc-800"
  291. >
  292. <span class="text-[#71717A] whitespace-nowrap">{{
  293. t("products.modelTitle")
  294. }}</span>
  295. <span class="text-white font-medium">{{
  296. product.model
  297. }}</span>
  298. </div>
  299. <div
  300. class="flex justify-between items-center gap-2 py-2 border-b border-zinc-800"
  301. >
  302. <span class="text-[#71717A] whitespace-nowrap">{{
  303. t("products.categoryTitle")
  304. }}</span>
  305. <span class="text-white font-medium"
  306. >{{ product.category
  307. }}<template v-if="product.tag">
  308. / {{ product.tag }}</template
  309. ></span
  310. >
  311. </div>
  312. <div
  313. v-if="product.tag"
  314. class="flex justify-between items-center gap-2 py-2 border-b border-zinc-800"
  315. >
  316. <span class="text-[#71717A] whitespace-nowrap">{{
  317. t("products.seriesTitle")
  318. }}</span>
  319. <span class="text-white font-medium">{{
  320. product.series?.join(" / ")
  321. }}</span>
  322. </div>
  323. <div
  324. class="flex justify-between items-center gap-2 py-2 border-b border-zinc-800"
  325. >
  326. <span class="text-[#71717A] whitespace-nowrap">{{
  327. t("products.usageTitle")
  328. }}</span>
  329. <span class="text-white font-medium">{{
  330. product.usage?.join(", ")
  331. }}</span>
  332. </div>
  333. <div
  334. v-if="product.capacities && product.capacities.length > 0"
  335. class="flex justify-between items-center py-2"
  336. >
  337. <span class="text-[#71717A]">{{
  338. t("products.capacitiesTitle")
  339. }}</span>
  340. <span class="text-white font-medium">{{
  341. product.capacities?.join(" / ")
  342. }}</span>
  343. </div>
  344. </div>
  345. </div>
  346. <!-- 产品描述 -->
  347. <div
  348. v-if="product.description"
  349. class="bg-zinc-900 rounded-lg p-2 md:p-6"
  350. >
  351. <h2 class="text-white text-xl font-medium mb-2 md:mb-6">
  352. {{ t("products.productDescription") }}
  353. </h2>
  354. <div
  355. class="text-[#71717A] leading-relaxed space-y-4 prose prose-invert max-w-none text-sm md:text-base"
  356. >
  357. {{ product.description }}
  358. </div>
  359. </div>
  360. <!-- 个人用户产品描述 -->
  361. <div
  362. v-if="product.meta?.audiences === 0"
  363. class="bg-zinc-900 rounded-lg p-2 md:p-6"
  364. >
  365. <div
  366. class="text-[#71717A] leading-relaxed space-y-4 prose prose-invert max-w-none text-sm md:text-base"
  367. >
  368. <ContentRenderer :value="product.content" />
  369. </div>
  370. </div>
  371. <!-- 相关产品 -->
  372. <div
  373. v-if="relatedProducts.length > 0"
  374. class="bg-zinc-900 rounded-lg p-2 md:p-6"
  375. >
  376. <h2 class="text-white text-xl font-medium mb-2 md:mb-6">
  377. {{ t("products.relatedProducts") }}
  378. </h2>
  379. <div class="grid grid-cols-2 md:grid-cols-3 gap-4">
  380. <nuxt-link
  381. v-for="relatedProduct in relatedProducts"
  382. :key="relatedProduct.id"
  383. :to="`${homepagePath}/products/${relatedProduct.id}`"
  384. class="group"
  385. >
  386. <div
  387. class="bg-zinc-800 rounded-lg p-4 transition-all duration-300 hover:bg-zinc-700"
  388. >
  389. <div
  390. class="aspect-square mb-4 overflow-hidden rounded-lg"
  391. >
  392. <img
  393. :src="relatedProduct.image"
  394. :alt="relatedProduct.title || relatedProduct.name"
  395. class="w-full h-full object-cover transition-transform duration-300 group-hover:scale-110"
  396. />
  397. </div>
  398. <h3
  399. class="text-white text-base md:text-lg font-medium mb-2 line-clamp-2"
  400. >
  401. {{ relatedProduct.title || relatedProduct.name }}
  402. </h3>
  403. <p class="text-[#71717A] text-sm line-clamp-2">
  404. {{ relatedProduct.summary }}
  405. </p>
  406. </div>
  407. </nuxt-link>
  408. </div>
  409. </div>
  410. </div>
  411. </div>
  412. <!-- 企业用户产品描述 -->
  413. <div
  414. v-if="product.meta?.audiences === 1"
  415. class="bg-zinc-900 rounded-lg p-2 md:p-6 mt-6 full-table-screen"
  416. >
  417. <div
  418. class="text-[#71717A] leading-relaxed space-y-4 prose prose-invert max-w-none text-sm md:text-base"
  419. >
  420. <ContentRenderer
  421. :value="product.content"
  422. />
  423. </div>
  424. </div>
  425. </div>
  426. </div>
  427. </div>
  428. </ErrorBoundary>
  429. </div>
  430. </template>
  431. <script setup lang="ts">
  432. /**
  433. * 产品详情页面
  434. * 展示产品主图、参数和描述
  435. */
  436. import { useErrorHandler } from "~/composables/useErrorHandler";
  437. import { useTableHighlight } from "~/composables/useTableHighlight";
  438. import { useRoute, useI18n, useAsyncData } from "#imports";
  439. import { queryCollection } from "#imports";
  440. import { ContentRenderer } from "#components";
  441. import { Swiper, SwiperSlide } from "swiper/vue";
  442. import {
  443. Navigation,
  444. Pagination,
  445. EffectFade,
  446. Thumbs,
  447. FreeMode,
  448. } from "swiper/modules";
  449. import type { Swiper as SwiperType } from "swiper";
  450. import "swiper/css";
  451. import "swiper/css/navigation";
  452. import "swiper/css/pagination";
  453. import "swiper/css/effect-fade";
  454. const { error, isLoading } = useErrorHandler();
  455. const { initTableHighlight } = useTableHighlight();
  456. const route = useRoute();
  457. const { locale, t } = useI18n();
  458. const id = route.params.id as string;
  459. const swiperInstance = ref<SwiperType | null>(null);
  460. const thumbsSwiper = ref<SwiperType | null>(null);
  461. // 图片状态
  462. const currentSlideIndex = ref(0);
  463. const isInitialLoading = ref(true); // 初始加载状态
  464. const isSlideThumbnailLoading = ref<boolean[]>([]);
  465. const slideThumbnailErrors = ref<boolean[]>([]);
  466. // 滚动跟随相关
  467. const scrollContainer = ref<HTMLElement | null>(null);
  468. const isSticky = ref(false);
  469. const homepagePath = computed(() => {
  470. return locale.value === "zh" ? "" : `/${locale.value}`;
  471. });
  472. interface Product {
  473. id: string;
  474. name: string;
  475. model: string;
  476. usage: string[];
  477. capacities: string[];
  478. category: string;
  479. categoryId: string;
  480. description: string;
  481. summary: string;
  482. image: string;
  483. gallery: string[];
  484. body: string;
  485. content?: any;
  486. tag?: string;
  487. series?: string[];
  488. meta?: {
  489. series?: string[];
  490. name?: string;
  491. title?: string;
  492. image?: string;
  493. summary?: string;
  494. audiences: number;
  495. };
  496. title?: string;
  497. }
  498. /**
  499. * 使用queryCollection获取产品数据
  500. */
  501. const { data: productContent } = await useAsyncData(
  502. `product-${id}`,
  503. async () => {
  504. try {
  505. // 使用queryCollection从content目录获取数据
  506. const content = await queryCollection("content")
  507. .where("path", "LIKE", `/products/${locale.value}/${id}`)
  508. .first();
  509. return content;
  510. } catch (err) {
  511. console.error("Error fetching product content:", err);
  512. error.value = new Error(t("products.loadError"));
  513. return null;
  514. }
  515. }
  516. );
  517. /**
  518. * 获取分类信息
  519. */
  520. const { data: categoryContent } = await useAsyncData(
  521. `category-${productContent.value?.meta?.categoryId}`,
  522. async () => {
  523. if (!productContent.value?.meta?.categoryId) return null;
  524. try {
  525. const content = await queryCollection("content")
  526. .where(
  527. "path",
  528. "LIKE",
  529. `/categories/${locale.value}/${productContent.value.meta?.categoryId}`
  530. )
  531. .first();
  532. return content;
  533. } catch (err) {
  534. console.error("Error fetching category:", err);
  535. return null;
  536. }
  537. },
  538. {
  539. immediate: !!productContent.value?.meta?.categoryId,
  540. }
  541. );
  542. /**
  543. * 使用计算属性解析产品数据
  544. */
  545. const product = computed<Product | any>(() => {
  546. if (!productContent.value) return null;
  547. // 提取产品数据
  548. const meta = productContent.value.meta || {};
  549. return {
  550. id: id,
  551. name: String(meta.name || productContent.value.title || ""),
  552. model: String(meta.model || ""),
  553. title: String(productContent.value.title || meta.name || ""),
  554. usage: Array.isArray(meta.usage) ? meta.usage : [],
  555. capacities: Array.isArray(meta.capacities) ? meta.capacities : [],
  556. category: categoryContent.value?.title || "",
  557. categoryId: meta.categoryId || "",
  558. description: productContent.value.description || "",
  559. summary: String(meta.summary || ""),
  560. image: String(meta.image || ""),
  561. gallery: Array.isArray(meta.gallery) ? meta.gallery : [],
  562. body: productContent.value.body || "",
  563. content: productContent.value,
  564. tag: meta.tag || "",
  565. series: Array.isArray(meta.series) ? meta.series : [],
  566. meta: {
  567. series: Array.isArray(meta.series) ? meta.series : [],
  568. name: String(meta.name || ""),
  569. title: String(productContent.value.title || ""),
  570. image: String(meta.image || ""),
  571. summary: String(meta.summary || ""),
  572. audiences: categoryContent.value?.meta?.audiences || 0,
  573. },
  574. };
  575. });
  576. // 初始化表格高亮功能
  577. initTableHighlight(computed(() => product.value?.model || ""));
  578. /**
  579. * 获取相关产品
  580. */
  581. const { data: relatedProductsContent } = await useAsyncData(
  582. `related-products-${id}`,
  583. async () => {
  584. try {
  585. // 获取产品列表
  586. const content = await queryCollection("content")
  587. .where("path", "LIKE", `/products/${locale.value}/%`)
  588. .all();
  589. return content;
  590. } catch (err) {
  591. console.error("Error fetching related products:", err);
  592. return [];
  593. }
  594. }
  595. );
  596. /**
  597. * 处理相关产品数据
  598. */
  599. const relatedProducts = computed(() => {
  600. if (!relatedProductsContent.value || !product.value) return [];
  601. // 获取当前产品的分类和系列
  602. const currentCategory = product.value.categoryId;
  603. const currentSeries = product.value.meta?.series || [];
  604. const currentProductId = id;
  605. return relatedProductsContent.value
  606. .filter((item: any) => {
  607. // 排除当前产品 - 多重检查确保排除
  608. if (item._path === `/products/${locale.value}/${id}`) return false;
  609. const meta = item.meta || {};
  610. if (meta.name === currentProductId) return false;
  611. const itemCategoryId = meta.categoryId || "";
  612. const itemSeries = Array.isArray(meta.series) ? meta.series : [];
  613. // 判断是否同类别或同系列
  614. const isSameCategory =
  615. currentCategory && itemCategoryId === currentCategory;
  616. const hasSameSeries =
  617. currentSeries.length > 0 &&
  618. itemSeries.some((series: string) => currentSeries.includes(series));
  619. // 返回同类别或同系列的产品
  620. return isSameCategory || hasSameSeries;
  621. })
  622. .map((item: any) => {
  623. const meta = item.meta || {};
  624. return {
  625. id: meta.name || "",
  626. name: meta.name || item.title || "",
  627. title: item.title || meta.name || "",
  628. image: meta.image || "",
  629. summary: meta.summary || "",
  630. category: meta.categoryId || "",
  631. series: Array.isArray(meta.series) ? meta.series : [],
  632. };
  633. })
  634. .slice(0, 6); // 最多显示6个相关产品
  635. });
  636. /**
  637. * 预加载下一张图片
  638. */
  639. function preloadNextImage(image: string) {
  640. currentSlideIndex.value =
  641. (currentSlideIndex.value + 1) % (product.value?.gallery?.length || 1);
  642. }
  643. /**
  644. * 处理图片加载完成
  645. */
  646. function handleSlideImageLoad(index: number) {
  647. isSlideThumbnailLoading.value[index] = false;
  648. slideThumbnailErrors.value[index] = false;
  649. // 检查是否所有图片都已加载
  650. const allImagesLoaded = isSlideThumbnailLoading.value.every(
  651. (status) => !status
  652. );
  653. if (allImagesLoaded) {
  654. isInitialLoading.value = false;
  655. }
  656. }
  657. /**
  658. * 处理图片加载错误
  659. */
  660. function handleSlideImageError(index: number) {
  661. isSlideThumbnailLoading.value[index] = false;
  662. slideThumbnailErrors.value[index] = true;
  663. }
  664. /**
  665. * 重试加载图片
  666. */
  667. function retryLoadSlideImage(index: number) {
  668. isSlideThumbnailLoading.value[index] = true;
  669. slideThumbnailErrors.value[index] = false;
  670. // 确定正确的图片URL
  671. const images = [product.value?.image, ...(product.value?.gallery || [])];
  672. const imageUrl = images[index];
  673. // 检查图片URL是否有效
  674. if (!imageUrl) {
  675. console.error("Invalid image URL:", index);
  676. slideThumbnailErrors.value[index] = true;
  677. isSlideThumbnailLoading.value[index] = false;
  678. return;
  679. }
  680. // 创建新的图片对象并设置超时
  681. const img = new Image();
  682. const timeoutId = setTimeout(() => {
  683. handleSlideImageError(index);
  684. }, 10000); // 10秒超时
  685. img.onload = () => {
  686. clearTimeout(timeoutId);
  687. handleSlideImageLoad(index);
  688. };
  689. img.onerror = (error) => {
  690. clearTimeout(timeoutId);
  691. console.error("Image load error:", { index, error });
  692. handleSlideImageError(index);
  693. };
  694. // 设置跨域属性
  695. img.crossOrigin = "anonymous";
  696. // 最后设置src以开始加载
  697. img.src = imageUrl;
  698. }
  699. // 页面加载时初始化状态
  700. onMounted(() => {
  701. // 初始化缩略图加载状态数组
  702. const galleryLength = (product.value?.gallery?.length || 0) + 1;
  703. isSlideThumbnailLoading.value = new Array(galleryLength).fill(true);
  704. slideThumbnailErrors.value = new Array(galleryLength).fill(false);
  705. // 设置初始加载状态
  706. isInitialLoading.value = true;
  707. // 预加载所有缩略图
  708. const images = [product.value?.image, ...(product.value?.gallery || [])];
  709. images.forEach((image, index) => {
  710. if (image) {
  711. const img = new Image();
  712. img.onload = () => handleSlideImageLoad(index);
  713. img.onerror = () => handleSlideImageError(index);
  714. img.src = image;
  715. }
  716. });
  717. // 添加滚动监听
  718. scrollContainer.value = document.querySelector(".max-w-screen-2xl");
  719. if (scrollContainer.value) {
  720. window.addEventListener("scroll", handleScroll, { passive: true });
  721. }
  722. });
  723. // 清理滚动监听
  724. onUnmounted(() => {
  725. if (scrollContainer.value) {
  726. window.removeEventListener("scroll", handleScroll);
  727. }
  728. });
  729. // 处理滚动事件
  730. function handleScroll() {
  731. if (!scrollContainer.value) return;
  732. const containerRect = scrollContainer.value.getBoundingClientRect();
  733. const scrollTop = window.scrollY || document.documentElement.scrollTop;
  734. // 当容器顶部距离视窗顶部小于100px时,启用sticky
  735. isSticky.value = containerRect.top < 100;
  736. }
  737. // SEO优化
  738. useHead(() => ({
  739. title: `${product.value?.name} - Hanye`,
  740. meta: [
  741. {
  742. name: "description",
  743. content: product.value?.description,
  744. },
  745. ],
  746. }));
  747. </script>
  748. <style lang="scss" scoped>
  749. /* 隐藏滚动条但保持滚动功能 */
  750. .scrollbar-hide {
  751. -ms-overflow-style: none; /* IE and Edge */
  752. scrollbar-width: none; /* Firefox */
  753. }
  754. .scrollbar-hide::-webkit-scrollbar {
  755. display: none; /* Chrome, Safari and Opera */
  756. }
  757. /* 图片过渡动画 */
  758. .main-image {
  759. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  760. }
  761. /* 缩略图悬停效果 */
  762. .thumbnail-item {
  763. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  764. }
  765. .thumbnail-item:hover {
  766. transform: translateY(-2px);
  767. }
  768. /* 缩略图选中效果 */
  769. .thumbnail-item.selected {
  770. transform: scale(1.05);
  771. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
  772. 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  773. }
  774. /* 产品信息卡片效果 */
  775. .info-card {
  776. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  777. }
  778. .info-card:hover {
  779. transform: translateY(-2px);
  780. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
  781. 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  782. }
  783. /* 滚动跟随效果 */
  784. .lg\:sticky {
  785. position: sticky;
  786. top: 6rem; /* 96px */
  787. transition: all 0.3s ease;
  788. z-index: 10;
  789. max-height: calc(100vh - 6rem);
  790. overflow-y: auto;
  791. }
  792. @media (max-width: 1024px) {
  793. .lg\:sticky {
  794. position: relative;
  795. top: 0;
  796. max-height: none;
  797. }
  798. }
  799. /* Swiper 样式定制 */
  800. .product-swiper {
  801. :deep(.swiper-pagination-bullet) {
  802. background-color: white;
  803. opacity: 0.5;
  804. }
  805. :deep(.swiper-pagination-bullet-active) {
  806. opacity: 1;
  807. background-color: theme("colors.cyan.400");
  808. }
  809. :deep(.swiper-button-next),
  810. :deep(.swiper-button-prev) {
  811. color: theme("colors.cyan.500");
  812. background-color: rgba(0, 0, 0, 0.3);
  813. width: 36px;
  814. height: 36px;
  815. border-radius: 50%;
  816. &:after {
  817. font-size: 16px;
  818. font-weight: bold;
  819. }
  820. &:hover {
  821. background-color: theme("colors.cyan.500");
  822. color: white;
  823. }
  824. }
  825. :deep(.swiper-button-disabled) {
  826. opacity: 0.35;
  827. cursor: auto;
  828. pointer-events: none;
  829. }
  830. :deep(.swiper-slide) {
  831. display: flex;
  832. align-items: center;
  833. justify-content: center;
  834. }
  835. }
  836. /* 缩略图Swiper样式 */
  837. .thumbs-swiper {
  838. overflow: visible;
  839. padding: 0.25rem;
  840. min-height: 6rem;
  841. :deep(.swiper-wrapper) {
  842. align-items: center;
  843. display: flex;
  844. min-height: 6rem;
  845. }
  846. :deep(.swiper-slide) {
  847. width: auto;
  848. height: auto;
  849. opacity: 0.7;
  850. transition: all 0.3s ease;
  851. display: flex;
  852. align-items: center;
  853. justify-content: center;
  854. }
  855. :deep(.swiper-slide-thumb-active) {
  856. opacity: 1;
  857. transform: scale(1.05);
  858. z-index: 1;
  859. }
  860. }
  861. /* 自定义缩略图导航按钮 */
  862. .swiper-thumb-next,
  863. .swiper-thumb-prev {
  864. &:focus {
  865. outline: none;
  866. }
  867. &.swiper-button-disabled {
  868. opacity: 0.3;
  869. cursor: default;
  870. background-color: rgba(0, 0, 0, 0.2);
  871. &:hover {
  872. background-color: rgba(0, 0, 0, 0.2);
  873. }
  874. }
  875. }
  876. /* 响应式调整 */
  877. @media (max-width: 768px) {
  878. .thumbs-swiper {
  879. padding: 0;
  880. :deep(.swiper-slide) {
  881. margin-right: 8px;
  882. }
  883. }
  884. /* 确保缩略图容器在移动设备上有足够空间 */
  885. .product-thumbnail-container {
  886. padding: 1rem;
  887. .swiper-thumb-prev {
  888. left: 0.5rem;
  889. width: 2rem;
  890. height: 2rem;
  891. }
  892. .swiper-thumb-next {
  893. right: 0.5rem;
  894. width: 2rem;
  895. height: 2rem;
  896. }
  897. }
  898. }
  899. /* 解决不同分辨率下缩略图大小问题 */
  900. .thumbnail-fixed-size {
  901. width: 100%;
  902. height: 100%;
  903. aspect-ratio: 1 / 1;
  904. position: relative;
  905. }
  906. /* 表格样式和高亮效果 */
  907. :deep(.full-table-screen .prose table) {
  908. @apply border-collapse border border-zinc-700 rounded-lg overflow-hidden;
  909. }
  910. :deep(.full-table-screen .prose thead) {
  911. @apply bg-zinc-800;
  912. }
  913. :deep(.full-table-screen .prose th) {
  914. @apply px-6 py-3 text-left text-base font-medium text-zinc-300 uppercase tracking-wider border-b border-zinc-700;
  915. }
  916. :deep(.full-table-screen .prose tbody) {
  917. @apply bg-zinc-900 divide-y divide-zinc-700;
  918. }
  919. :deep(.full-table-screen .prose td) {
  920. @apply px-6 py-4 text-sm text-zinc-300 border-b border-zinc-700/50;
  921. }
  922. :deep(.full-table-screen .prose tr) {
  923. @apply transition-colors duration-200;
  924. }
  925. :deep(.full-table-screen .prose tr:hover:not(.highlighted-model-row)) {
  926. @apply bg-zinc-800/50;
  927. }
  928. /* 高亮当前型号对应的行 */
  929. :deep(.full-table-screen .prose tr.highlighted-model-row) {
  930. @apply bg-cyan-500/20 border border-cyan-400/50;
  931. }
  932. :deep(.full-table-screen .prose tr.highlighted-model-row td) {
  933. @apply text-cyan-400 font-medium;
  934. }
  935. /* 表格响应式处理 */
  936. @media (max-width: 640px) {
  937. :deep(.prose table) {
  938. font-size: 0.875rem;
  939. }
  940. :deep(.full-table-screen .prose th),
  941. :deep(.full-table-screen .prose td) {
  942. @apply px-3 py-2;
  943. }
  944. }
  945. /* 表格响应式容器 */
  946. :deep(.full-table-screen .prose) {
  947. /* 为包含表格的容器添加水平滚动 */
  948. & > *:has(table) {
  949. overflow-x: auto;
  950. -webkit-overflow-scrolling: touch;
  951. scrollbar-width: thin;
  952. scrollbar-color: theme("colors.cyan.400") theme("colors.zinc.800");
  953. }
  954. /* 自定义滚动条样式 */
  955. & > *:has(table)::-webkit-scrollbar {
  956. height: 8px;
  957. }
  958. & > *:has(table)::-webkit-scrollbar-track {
  959. background: theme("colors.zinc.800");
  960. border-radius: 4px;
  961. }
  962. & > *:has(table)::-webkit-scrollbar-thumb {
  963. background: theme("colors.cyan.400");
  964. border-radius: 4px;
  965. }
  966. & > *:has(table)::-webkit-scrollbar-thumb:hover {
  967. background: theme("colors.cyan.300");
  968. }
  969. }
  970. /* 小屏幕表格优化 */
  971. @media (max-width: 768px) {
  972. :deep(.full-table-screen .prose table) {
  973. min-width: 100%;
  974. white-space: nowrap;
  975. }
  976. :deep(.full-table-screen .prose th),
  977. :deep(.full-table-screen .prose td) {
  978. @apply px-2 py-2 text-xs;
  979. min-width: 100px; /* 确保最小宽度 */
  980. }
  981. /* 高亮列在小屏幕上更明显 */
  982. :deep(.full-table-screen .prose td.highlighted-model-column),
  983. :deep(.full-table-screen .prose th.highlighted-model-column) {
  984. @apply bg-cyan-500/30;
  985. position: sticky;
  986. z-index: 10;
  987. }
  988. :deep(.full-table-screen .prose td.highlighted-model-column)::before,
  989. :deep(.full-table-screen .prose th.highlighted-model-column)::before {
  990. width: 4px;
  991. }
  992. }
  993. /* 超小屏幕处理 */
  994. @media (max-width: 480px) {
  995. :deep(.full-table-screen .prose th),
  996. :deep(.full-table-screen .prose td) {
  997. @apply px-1 py-1 text-xs;
  998. min-width: 80px;
  999. }
  1000. /* 为高亮列添加固定位置,确保始终可见 */
  1001. :deep(.full-table-screen .prose td.highlighted-model-column),
  1002. :deep(.full-table-screen .prose th.highlighted-model-column) {
  1003. position: sticky;
  1004. left: 0;
  1005. z-index: 20;
  1006. box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
  1007. }
  1008. }
  1009. /* 列高亮基础样式 */
  1010. :deep(.full-table-screen .prose td.highlighted-model-column),
  1011. :deep(.full-table-screen .prose th.highlighted-model-column) {
  1012. @apply bg-cyan-500/20 text-cyan-400 font-medium;
  1013. position: relative;
  1014. }
  1015. :deep(.full-table-screen .prose td.highlighted-model-column)::before,
  1016. :deep(.full-table-screen .prose th.highlighted-model-column)::before {
  1017. content: "";
  1018. position: absolute;
  1019. left: 0;
  1020. top: 0;
  1021. bottom: 0;
  1022. width: 3px;
  1023. background-color: theme("colors.cyan.400");
  1024. }
  1025. /* 表格行悬停效果 */
  1026. :deep(.full-table-screen .prose tr:hover td:not(.highlighted-model-column)) {
  1027. @apply bg-zinc-800/30;
  1028. }
  1029. /* 表格响应式包装器样式 */
  1030. :deep(.table-responsive-wrapper) {
  1031. border-radius: 8px;
  1032. background: theme("colors.zinc.900");
  1033. margin: 1rem 0;
  1034. }
  1035. :deep(.scroll-indicator) {
  1036. animation: fadeInOut 3s ease-in-out infinite;
  1037. }
  1038. @keyframes fadeInOut {
  1039. 0%,
  1040. 100% {
  1041. opacity: 0.6;
  1042. }
  1043. 50% {
  1044. opacity: 1;
  1045. }
  1046. }
  1047. /* 优化表格在响应式包装器中的显示 */
  1048. :deep(.table-responsive-wrapper table) {
  1049. margin: 0;
  1050. border-radius: 0;
  1051. }
  1052. /* 滚动条增强 */
  1053. :deep(.table-responsive-wrapper::-webkit-scrollbar) {
  1054. height: 12px;
  1055. }
  1056. :deep(.table-responsive-wrapper::-webkit-scrollbar-track) {
  1057. background: theme("colors.zinc.800");
  1058. border-radius: 6px;
  1059. margin: 0 8px;
  1060. }
  1061. :deep(.table-responsive-wrapper::-webkit-scrollbar-thumb) {
  1062. background: linear-gradient(
  1063. 45deg,
  1064. theme("colors.cyan.500"),
  1065. theme("colors.cyan.400")
  1066. );
  1067. border-radius: 6px;
  1068. border: 2px solid theme("colors.zinc.800");
  1069. }
  1070. :deep(.table-responsive-wrapper::-webkit-scrollbar-thumb:hover) {
  1071. background: linear-gradient(
  1072. 45deg,
  1073. theme("colors.cyan.400"),
  1074. theme("colors.cyan.300")
  1075. );
  1076. }
  1077. /* 简化的表格响应式处理 - 覆盖之前的复杂样式 */
  1078. :deep(.full-table-screen .prose table) {
  1079. min-width: 700px !important;
  1080. width: 100% !important;
  1081. white-space: nowrap;
  1082. }
  1083. :deep(.full-table-screen .prose th),
  1084. :deep(.full-table-screen .prose td) {
  1085. white-space: nowrap !important;
  1086. min-width: 100px;
  1087. }
  1088. /* 移动设备优化 */
  1089. @media (max-width: 768px) {
  1090. :deep(.full-table-screen .prose table) {
  1091. min-width: 800px !important;
  1092. font-size: 0.875rem;
  1093. }
  1094. :deep(.full-table-screen .prose th),
  1095. :deep(.full-table-screen .prose td) {
  1096. min-width: 80px;
  1097. padding: 0.5rem 0.25rem !important;
  1098. font-size: 0.75rem;
  1099. }
  1100. }
  1101. @media (max-width: 480px) {
  1102. :deep(.full-table-screen .prose table) {
  1103. min-width: 600px !important;
  1104. }
  1105. :deep(.full-table-screen .prose th),
  1106. :deep(.full-table-screen .prose td) {
  1107. min-width: 90px !important;
  1108. padding: 0.25rem 0.375rem !important;
  1109. font-size: 0.75rem !important;
  1110. }
  1111. }
  1112. /* 优化单元格宽度 - 更合适的显示空间 */
  1113. :deep(.full-table-screen .prose table) {
  1114. min-width: 1000px !important; /* 增加整体表格宽度 */
  1115. }
  1116. :deep(.full-table-screen .prose th),
  1117. :deep(.full-table-screen .prose td) {
  1118. min-width: 150px !important; /* 增加单元格最小宽度 */
  1119. max-width: 300px; /* 设置最大宽度避免过宽 */
  1120. padding: 0.75rem 1rem !important; /* 增加内边距 */
  1121. }
  1122. /* 第一列(通常是标题列)给更多宽度 */
  1123. :deep(.full-table-screen .prose th:first-child),
  1124. :deep(.full-table-screen .prose td:first-child) {
  1125. min-width: 200px !important;
  1126. }
  1127. /* 针对不同屏幕尺寸的优化 */
  1128. @media (max-width: 1024px) {
  1129. :deep(.full-table-screen .prose table) {
  1130. min-width: 900px !important;
  1131. }
  1132. :deep(.full-table-screen .prose th),
  1133. :deep(.full-table-screen .prose td) {
  1134. min-width: 130px !important;
  1135. padding: 0.5rem 0.75rem !important;
  1136. }
  1137. }
  1138. @media (max-width: 768px) {
  1139. :deep(.full-table-screen .prose table) {
  1140. min-width: 800px !important;
  1141. }
  1142. :deep(.full-table-screen .prose th),
  1143. :deep(.full-table-screen .prose td) {
  1144. min-width: 120px !important;
  1145. padding: 0.5rem 0.5rem !important;
  1146. font-size: 0.875rem !important;
  1147. }
  1148. }
  1149. @media (max-width: 640px) {
  1150. :deep(.full-table-screen .prose table) {
  1151. min-width: 700px !important;
  1152. }
  1153. :deep(.full-table-screen .prose th),
  1154. :deep(.full-table-screen .prose td) {
  1155. min-width: 100px !important;
  1156. padding: 0.375rem 0.5rem !important;
  1157. font-size: 0.8rem !important;
  1158. }
  1159. }
  1160. @media (max-width: 480px) {
  1161. :deep(.full-table-screen .prose table) {
  1162. min-width: 600px !important;
  1163. }
  1164. :deep(.full-table-screen .prose th),
  1165. :deep(.full-table-screen .prose td) {
  1166. min-width: 90px !important;
  1167. padding: 0.25rem 0.375rem !important;
  1168. font-size: 0.75rem !important;
  1169. }
  1170. }
  1171. /* 单元格内容截断和悬停显示 */
  1172. :deep(.full-table-screen .prose th),
  1173. :deep(.full-table-screen .prose td) {
  1174. position: relative;
  1175. overflow: hidden !important;
  1176. text-overflow: ellipsis !important;
  1177. white-space: nowrap !important;
  1178. }
  1179. /* 悬停时显示完整内容 */
  1180. :deep(.full-table-screen .prose th:hover),
  1181. :deep(.full-table-screen .prose td:hover) {
  1182. overflow: visible !important;
  1183. white-space: normal !important;
  1184. z-index: 100;
  1185. background-color: theme("colors.zinc.800") !important;
  1186. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
  1187. 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  1188. border-radius: 4px;
  1189. }
  1190. /* 高亮列的悬停效果 */
  1191. :deep(.full-table-screen .prose th.highlighted-model-column:hover),
  1192. :deep(.full-table-screen .prose td.highlighted-model-column:hover) {
  1193. background-color: theme("colors.cyan.600") !important;
  1194. color: white !important;
  1195. }
  1196. /* 确保悬停时的文本不会被遮挡 */
  1197. :deep(.full-table-screen .prose table) {
  1198. position: relative;
  1199. z-index: 1;
  1200. }
  1201. :deep(.full-table-screen .prose th:hover),
  1202. :deep(.full-table-screen .prose td:hover) {
  1203. position: relative;
  1204. z-index: 101;
  1205. }
  1206. </style>